var init = 0; var init2 = 0;
var innerAudioContext;//背景音乐对象
var button;//按钮音乐对象
var app = getApp();
Page({
  data: {
    windowWidth: "",
    windowHeight: "",
    score: "",//分数
    over: 0,//排名
    maskIndex:0,
    request_url: '',//url地址
    mask: "",//面具地址
    hide:"",//是否戴上面具
    wearTap:""//戴上面具按钮事件绑定
  },
  getMask: function () {
    let vm = this

  },
  onLoad: function (options) {
    let vm = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        vm.setData({
          windowWidth: res.windowWidth//可使用宽度
        })
        vm.setData({
          windowHeight: res.screenHeight//可使用高度
        })
        var request_url = wx.getStorageSync('request_url')
        vm.setData({
          maskIndex: options.maskIndex,//面具
          // maskIndex: 6,//面具
          request_url: request_url,
          score: options.scoreSum,
          over: options.exceedRate,
          hide: options.hide//是否能戴上面具
        })
        if (vm.data.hide.substring(vm.data.hide.length - 10, vm.data.hide.length - 8)=='un'){
          vm.setData({
            wearTap:""
          })
        }else{
          vm.setData({
            wearTap: "wear"
          })
        }
        wx.request({
          url:vm.data.request_url+'/MianJuJiang/img/getReadyImg/'+ vm.data.maskIndex,
          method: 'GET',
          success: function (res) {
            console.log("后台请求成功");
            console.log(res.data)
            vm.setData({
              mask: vm.data.request_url + "/" + res.data["imgData"]
            })
          },
          fail: function (res) {
            console.log("后台请求失败");
            console.log(res.data);
          }
        })
      }
    });
  },
  wear: function () {
    let vm=this
    this.button("button1", true, false);
    wx.redirectTo({
      //跳转
      url: '../photo/photo?maskIndex=' + vm.data.maskIndex,
    })
  },
  returnWorkstation: function () {
    this.button("button1", true, false);
    wx.redirectTo({
      //跳转
      url: '../level/level',
    })
  },
  button: function (u, a, l) {
    if (init2 == 0) {
      init2++;
      button = wx.createInnerAudioContext()
      button.autoplay = a;
      var urlKey = u;
      var savedFilePath = wx.getStorageSync(urlKey);
      button.src = savedFilePath;
      button.loop = l;
    } else {
      button.autoplay = a;
      button.src = wx.getStorageSync(u);
      button.loop = l;
    }
  },
})